import type { Emitter } from "mitt";
import mitt from "mitt";

/** 全局公共事件需要在此处添加类型 */
type Events = {
  levelOptionChange: any;
};

export const emitter: Emitter<Events> = mitt<Events>();

/**
 * 显示任务详情的状态*/
export const TASK_DETAIL_STATUS = [0, 1, 2];
/**
 * 显示任务执行结果详情的状态*/
export const TASK_RESULT_DETAIL_STATUS = [3, 6];
// 根据后端巡检任务字典接口返回内容配置
export const TAG_CONFIG = {
  0: {
    color: "#909399",
    statussDesc: ["已取消"]
  }, // 已取消
  1: {
    color: "#F59E0B",
    statussDesc: ["未开始"]
  }, // 未开始
  2: {
    color: "#F59E0B",
    statussDesc: ["待接单"]
  }, // 待接单
  3: {
    color: "#F59E0B",
    statussDesc: [" 待接单", "超期"]
  }, // 待接单(超期)
  4: {
    color: "#3B82F6",
    statussDesc: ["执行中"]
  }, // 执行中
  5: {
    color: "#3B82F6",
    statussDesc: ["执行中", "超期"]
  }, // 执行中(超期)
  6: {
    color: "#10B981",
    statussDesc: ["已完成"]
  }, // 已完成
  7: {
    color: "#10B981",
    statussDesc: ["已完成", "超期"]
  } // 已完成(超期)
};
/**
 * 巡检任务详情——基础信息——表格配置
 */
export const INSPECTTASKDETAIL_BASEINFO_COLUMNS = [
  [
    {
      label: "科室",
      value: "classNameDesc"
    },
    {
      label: "巡检类型",
      value: "inspectTypeDesc"
    },
    {
      label: "任务分配",
      value: "groupName"
    }
  ],
  [
    {
      label: "任务开始时间",
      value: "startTime"
    },
    {
      label: "任务结束时间",
      value: "endTime"
    },
    {
      label: "任务宽泛期",
      value: "extendDuration"
    }
  ],

  [
    {
      label: "说明",
      value: "description"
    }
  ]
];
/**
 * 巡检任务详情——巡检内容——表格配置
 */
export const INSPECTTASKDETAIL_CONTENT_COLUMNS = [
  // { prop: "expend", minWidth: "55", fixed: "left" },
  { prop: "checkRuleNo", label: "巡检项", minWidth: "350", showOverflowTooltip: true, fixed: "left" },
  { prop: "checkRuleName", label: "巡检内容", minWidth: "500", showOverflowTooltip: true },
  { prop: "facName", label: "内容范围", minWidth: "500", showOverflowTooltip: true, facName: true }
  // { prop: "eqpTypeName", label: "设备类型", minWidth: "160", showOverflowTooltip: true },
  // { prop: "ruleTypeName", label: "规则类型", minWidth: "160", showOverflowTooltip: true },
  // { prop: "recommendDay", label: "建议工作天数", minWidth: "160", showOverflowTooltip: true }
];
/**
 * 巡检任务详情——巡检设备——表格配置
 */
export const INSPECTTASKDETAIL_EQUIP_COLUMNS = [
  { prop: "drag", minWidth: "60" },
  { prop: "eqpId", label: "设备编号", minWidth: "160", showOverflowTooltip: true, fixed: "left" },
  { prop: "eqpName", label: "设备名称", minWidth: "160", showOverflowTooltip: true, fixed: "left" },
  { prop: "eqpSys", label: "设备系统", minWidth: "160", showOverflowTooltip: true },
  { prop: "typeName", label: "设备类型", minWidth: "160", showOverflowTooltip: true },
  { prop: "specification", label: "设备型号", minWidth: "160", showOverflowTooltip: true },
  { prop: "positionName", label: "位置信息", minWidth: "160", showOverflowTooltip: true }
];
/**
 * 巡检任务详情——巡检设备——表格配置——只读
 */
export const INSPECTTASKDETAIL_EQUIP_COLUMNS_READONLY = [
  { prop: "index", minWidth: "60" },
  { prop: "eqpId", label: "设备编号", minWidth: "160", showOverflowTooltip: true, fixed: "left" },
  { prop: "eqpName", label: "设备名称", minWidth: "160", showOverflowTooltip: true, fixed: "left" },
  { prop: "eqpSys", label: "设备系统", minWidth: "160", showOverflowTooltip: true },
  { prop: "typeName", label: "设备类型", minWidth: "160", showOverflowTooltip: true },
  { prop: "specification", label: "设备型号", minWidth: "160", showOverflowTooltip: true },
  { prop: "positionName", label: "位置信息", minWidth: "160", showOverflowTooltip: true }
];
/**
 * 巡检任务详情——待执行———计划生成——tab
 */
export const TAB_EXECUTE_LIST = [
  { name: "task", label: "巡检任务" },
  { name: "plan", label: "巡检计划" }
];
export const TAB_LIST = [
  { name: "task", label: "巡检任务" },
  { name: "plan", label: "巡检计划" },
  { name: "exception", label: "巡检异常信息" }
];

/**
 * 巡检任务详情——待执行———计划生成——巡检计划——基本信息
 */
export const INSPECTTASKDETAIL_BASEINFO_COLUMNS_PLAN = [
  [
    {
      label: "巡检计划编号",
      value: "planNo"
    },
    {
      label: "地块",
      value: "checkAreaDesc"
    },
    {
      label: "任务分配",
      value: "checkGroupDesc"
    }
  ],
  [
    {
      label: "说明",
      value: "description"
    }
  ]
];
/**
 * 巡检任务——当前登录用户角色判断
 */
export const USER_ROLE = Object.freeze({
  /**
   * 是否是创建人
   */
  // isCreater: (data: object) => {
  //   const { userId } = JSON.parse(localStorage.getItem("userInfo"));
  //   if (userId) {
  //   } else {
  //     return false;
  //   }
  // },
  /**
   * 是否是执行人
   */
  isoperator: (data: { canExecute: boolean }) => {
    return data?.canExecute;
  },
  /**
   * 是否是验收人
   */
  isAccepter: (data: { acceptorId: string }) => {
    const { userId } = JSON.parse(localStorage.getItem("userInfo"));
    if (userId) {
      return data?.acceptorId === userId;
    } else {
      return false;
    }
  }
});
